package com.example.demo2.service.impl;

import com.example.demo2.dao.TestMapper;
import com.example.demo2.service.ICheckService;
import com.example.demo2.service.ITestCase4RequiresNewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import static com.example.demo2.utils.HttpUtils.check;

@Slf4j
@Service
public class TestCase4RequiresNewServiceImpl implements ITestCase4RequiresNewService {
    @Autowired
    private TestMapper testMapper;
    @Autowired
    private ICheckService checkService;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void case4RequiresNew() {
        log.info("------------------------------------------------");
        testMapper.insert("case4.1");
        check();
        checkService.check();
        log.info("此处只能看到自己事务的 4.1 看不到 4");
//        log.info("此处表现正常，事务在结束后提交");
//        testMapper.delete("case4.1");
    }
}
